package com.elai.operate.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.enums.BusinessType;
import com.elai.operate.domain.OperateChannelConfig;
import com.elai.operate.service.IOperateChannelConfigService;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.common.core.page.TableDataInfo;

/**
 * 推送通道管理Controller
 * 
 * @author elai
 * @date 2021-10-18
 */
@RestController
@RequestMapping("/operate/chanelconfig")
public class OperateChannelConfigController extends BaseController
{
    @Autowired
    private IOperateChannelConfigService operateChannelConfigService;

    /**
     * 查询推送通道管理列表
     */
    @PreAuthorize("@ss.hasPermi('operate:chanelconfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(OperateChannelConfig operateChannelConfig)
    {
        startPage();
        List<OperateChannelConfig> list = operateChannelConfigService.selectOperateChannelConfigList(operateChannelConfig);
        return getDataTable(list);
    }

    @GetMapping("/getChanneConfiglList")
    public AjaxResult getChanneConfiglList(OperateChannelConfig operateChannelConfig)
    {
        List result=new ArrayList();
        operateChannelConfig.setStatus("Y");
        operateChannelConfig.setIsPreset("Y");
        List<OperateChannelConfig> presetlist = operateChannelConfigService.selectOperateChannelConfigList(operateChannelConfig);
        Map preset=new HashMap<>();
        preset.put("label","预制通道("+presetlist.size()+")");
        preset.put("options",presetlist);
        result.add(preset);

        operateChannelConfig.setIsPreset("N");
        List<OperateChannelConfig> unpresetlist = operateChannelConfigService.selectOperateChannelConfigList(operateChannelConfig);
        Map unpreset=new HashMap<>();
        unpreset.put("label","非预制通道("+unpresetlist.size()+")");
        unpreset.put("options",unpresetlist);
        result.add(unpreset);

        return AjaxResult.success(result);
    }
    /**
     * 导出推送通道管理列表
     */
    @PreAuthorize("@ss.hasPermi('operate:chanelconfig:export')")
    @Log(title = "推送通道管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OperateChannelConfig operateChannelConfig)
    {
        List<OperateChannelConfig> list = operateChannelConfigService.selectOperateChannelConfigList(operateChannelConfig);
        ExcelUtil<OperateChannelConfig> util = new ExcelUtil<OperateChannelConfig>(OperateChannelConfig.class);
        return util.exportExcel(list, "推送通道管理数据");
    }

    /**
     * 获取推送通道管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('operate:chanelconfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(operateChannelConfigService.selectOperateChannelConfigById(id));
    }

    /**
     * 新增推送通道管理
     */
    @PreAuthorize("@ss.hasPermi('operate:chanelconfig:add')")
    @Log(title = "推送通道管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperateChannelConfig operateChannelConfig)
    {
        return toAjax(operateChannelConfigService.insertOperateChannelConfig(operateChannelConfig));
    }

    /**
     * 修改推送通道管理
     */
    @PreAuthorize("@ss.hasPermi('operate:chanelconfig:edit')")
    @Log(title = "推送通道管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperateChannelConfig operateChannelConfig)
    {
        return toAjax(operateChannelConfigService.updateOperateChannelConfig(operateChannelConfig));
    }

    /**
     * 删除推送通道管理
     */
    @PreAuthorize("@ss.hasPermi('operate:chanelconfig:remove')")
    @Log(title = "推送通道管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(operateChannelConfigService.deleteOperateChannelConfigByIds(ids));
    }
}
